<template>
  <div>
    <ul class="new-list">
      <li v-for="(item, index) in nwesList" :key="index">
        <router-link :to="'/home/newlist/newinfo/'+item.id" class="new-item">
          <div class="img-box">
            <img :src="item.litpic" alt>
          </div>
          <div class="info-box">
            <p>{{item.title}}</p>
            <div class="list-foot">
              <div>{{item.pubdate|formatDate}}</div>
              <div>点击：{{item.click}}</div>
            </div>
          </div>
          <div style="clear:both"></div>
        </router-link>
      </li>
    </ul>
    <mt-button v-show="flag" type="danger" size="large" plain @click="getmore" ref="more">加载更多</mt-button>
    <mt-button v-show="flag1" type="danger" size="large" plain  ref="more">没有更多了</mt-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      nwesList: [],
      id: "",
      flag: false,
      flag1: false,
      page: 1,
      count: 0
    };
  },
  mounted: function() {},
  methods: {
    getnews() {
      this.$http.get("http://192.168.0.104/linshi/api/get_list.php?typid=5&page=" + this.page)
        .then(res => {
          if (res.status == 200) {
            if (this.nwesList.length < 1) {
              this.nwesList = res.body.list;
              this.count = res.body.count;
            } else {
              this.nwesList = this.nwesList.concat(res.body.list);
            }
          } else {
            console.log("获取失败");
          }
          if (this.nwesList.length == parseInt(this.count)) {
            this.flag = false;
            this.flag1 = true;
          } else {
            this.flag = true;
          }

          console.log(this.nwesList);
        });
    },
    getmore() {
      if(this.nwesList.length == parseInt(this.count)){
        return
      }
      this.page++;
      this.getnews();
      console.log(this.page);
    }
  },
  components: {},
  created() {
    this.getnews();
     this.$emit("changTit",true,'新闻列表');
  }
};
</script>

<style lang="scss" scoped>
.new-list {
  width: 100%;
  box-sizing: border-box;
  padding-left: 20px;
  font-size: 12px;
  margin: 0;
  li {
    padding: 10px 20px 10px 0;
    list-style: none;
    border-bottom: 1px solid #ccc;
    .new-item {
      .img-box {
        padding-right: 10px;
        float: left;
        img {
          height: 42px;
          object-fit: fill;
          width: 42px;
        }
      }
      .info-box {
        float: left;
        overflow: hidden;
        width: 80%;
        p {
          line-height: 1.25em;
          margin: 0;
          display: inline-block;
        }
        .list-foot {
          display: flex;
          justify-content: space-between;
        }
      }
    }
  }
}
</style>
